<?php
function match($user, $resident){
	
	$query = "select bid from users_behaviour where username = '$user'";
	$result = mysql_query($query);
	$userArray = array();
	while($rows = mysql_fetch_array($result)){
		$bid = $rows["bid"];
		$userArray[] = $bid;
	}
	
	
	$query = "select bid from users_behaviour where username = '$resident'";
	$result = mysql_query($query);
	$residentArray = array();
	while($rows = mysql_fetch_array($result)){
		$bid = $rows["bid"];
		$residentArray[] = $bid;
	}
	
	
	//difference and similarity in behaviours
	$diff = array_merge(array_diff($residentArray,$userArray), array_diff($userArray,$residentArray));
	//print "diff-dunno what";
	$sim = array_intersect($userArray, $residentArray);
	//user's beh diff from resident
	$udiff = array_diff($userArray, $sim);
	//resident's beh diff from user
	$rdiff = array_diff($residentArray, $sim);
	
	$query = "select bid from behaviour";
	$result = mysql_query($query);
	$behaviours = array();
	while($rows = mysql_fetch_array($result)){
		$behaviours[] = $rows["bid"];
	}
	
	$mergedDiffAndSim = array_merge($sim, $diff);
	
	//both users did not choose these behaviours
	$notChosenBehaviour = array_diff($behaviours, $mergedDiffAndSim);
	
	$mergedSimAndNotChoosen = array_merge($sim, $notChosenBehaviour);
	
	$percentage = (count($mergedSimAndNotChoosen)/10) * 100;
	
	return $percentage;
}

?>